home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT1-5 / COMPSTR.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-27  |  1.8 KB  |  57 lines

  1. ;
  2. ;       Program CompStr ( Chapter 4 )
  3. ;
  4. .model small
  5. .stack
  6. .data
  7. StrBuf  db        80
  8. ActLen  db        0
  9. Str1    db        80 dup (' ')
  10. Str2    db        'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  11. .code
  12.         include   maclib.inc
  13. .startup
  14.         push      ds
  15.         pop       es
  16.         NewLine
  17.         Outmsg    'Enter alphabet characters: ABCD...  in capital letters:  '
  18.         NewLine
  19.         mov       ah,0Ah               ; function 0Ah - input string
  20.         lea       dx,StrBuf            ; DS:DX - buffer address
  21.         int       21h                  ; DOS service call
  22.         .IF       ActLen < 1
  23.         .exit     1
  24.         .ENDIF
  25.         lea       di,Str2              ; ES:DI point to string 2 (comparand)
  26.         lea       si,Str1              ; DS:SI point to string 1 (entered)
  27.         mov       ch,0                 ; clear high byte of CX
  28.         mov       cl,ActLen            ; CX contains actual length of string
  29.         .IF       cx > LengthOf Str2
  30.         mov       cx,LengthOf Str2
  31.         .ENDIF
  32.         NewLine
  33.         OutMsg    'Entered text:   '
  34.         OutBytes Str1,cx
  35.         NewLine
  36.         OutMsg    'Compared with:  '
  37.         OutBytes Str2,LengthOf Str2
  38.         NewLine
  39.         cld                            ; process strings from left to right
  40. repe    cmpsb                          ; compare strings
  41.         .IF ZERO?
  42.                   OutMsg     'Right!'
  43.         .ELSE
  44.                   mov        al,ActLen
  45.                   cbw
  46.                   sub        ax,cx
  47.                   OutMsg     'Character at position  '
  48.                   OutInt     ax
  49.                   OutMsg     ' is: "'
  50.                   OutChar    [si-1]
  51.                   OutMsg     '"; must be "'
  52.                   OutChar    [di-1]
  53.         .ENDIF
  54.         Newline
  55. .exit 0
  56.         end
  57.